let str = '     hello world  '
// 去除前边空格
function removePrefixSpace() {
  let reg = /^\s+/
  let st = str.replace(reg, '')
  console.log('$' + st + '$') // $hello world  $
}
removePrefixSpace()

// 去除后面的空格
function removeSuffixSpace() {
  let reg = /\s+$/
  let st = str.replace(reg, '')
  console.log('$' + st + '$') // $     hello world$
}
removeSuffixSpace()

// 清空所有的空格
function trimAll() {
  let reg = /\s/g
  let st = str.replace(reg, '')
  console.log('$' + st + '$') // $helloworld$
}
trimAll()

// 去除首尾的空格
function trims() {
  let reg = /(^\s+)|(\s+$)/g
  let st = str.replace(reg, '')
  console.log('$' + st + '$') // $hello world$
}
trims()

//
